<script setup name="AnnualFee">
import { Edit, View } from '@element-plus/icons-vue'
import { ElMessageBox } from 'element-plus'
import Message from 'vue-m-message'
import annualFeeService from '@/api/annualFee/index.js'
import YearFeeDetailModal from '@/views/system/annualFee/components/YearFeeDetailModal.vue'
import Toolbar from '@/components/Toolbar/Toolbar.vue'
import { tableCheckChane } from '@/utils/index.js'
import { yearFeeSearchConfig, yearFeeTableColumns } from '@/views/system/annualFee/yearFeeConfig.js'

const { proxy } = getCurrentInstance()
const pagerConfig = ref({
  total: 0,
  currentPage: 1,
  pageSize: 10,
})
const ids = ref([])
const tableData = ref([])
const queryParam = ref({})
const visible = ref(false)
const detailParams = ref({})
const annualFeeId = ref(null)
onMounted(() => {
  getList()
})

function getList() {
  const params = {
    pageSize: pagerConfig.value.pageSize,
    pageNum: pagerConfig.value.currentPage,
    status: '0',
    ...queryParam.value,
  }
  annualFeeService.list(params).then((res) => {
    const { rows, total } = res
    pagerConfig.value.total = total
    tableData.value = rows
  })
}

function handleAdd() {

}

function handleDelete() {

}
function handlePageChange({ currentPage, pageSize }) {
  pagerConfig.value.currentPage = currentPage
  pagerConfig.value.pageSize = pageSize
  getList()
}

function handleCheckChange(data) {
  ids.value = tableCheckChane(data, '', ids.value)
}

function handleExport() {
  proxy.download('', { ...queryParam.value, exportIds: ids.value.join(',') }, `_${new Date().getTime()}.xlsx`)
}

function handleSearch(params) {
  queryParam.value = params
  pagerConfig.value.currentPage = 1
  getList()
}

function handleView(row) {
  detailParams.value = row
  visible.value = true
}

function handleEditRemark(row) {
  const { remark } = row
  ElMessageBox.prompt('请输入备注', '提示', {
    inputType: 'textarea',
    inputValue: remark,
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    beforeClose: (action, instance, done) => {
      if (action === 'confirm') {
        annualFeeService.update({ ...row, remark: instance.inputValue, isUpdateRemark: '1' }).then((res) => {
          const code = res.code
          if (code === 200) {
            Message.success('修改成功')
            done()
          }
        })
      }
      else {
        done()
      }
    },
  }).then((res) => {
    getList()
  })
}
</script>

<template>
  <div class="app-container">
    <el-card shadow="never" class="">
      <SearchBar :search-config="yearFeeSearchConfig" @search="handleSearch" />
    </el-card>
    <el-card shadow="never" class="mt-2">
      <Toolbar>
        <!--        <el-button -->
        <!--          v-hasPermi="['system:annualFee:remove']" -->
        <!--          type="danger" -->
        <!--          class="el-gradient-danger" -->
        <!--          :disabled="ids.length === 0" -->
        <!--          @click="handleDelete(null)" -->
        <!--        > -->
        <!--          删除 -->
        <!--          <el-icon class="el-icon&#45;&#45;right"> -->
        <!--            <Delete /> -->
        <!--          </el-icon> -->
        <!--        </el-button> -->
        <el-button
          v-hasPermi="['system:annualFee:export']"
          type="warning"
          class="el-gradient-warning"
          @click="handleExport()"
        >
          导出
          <el-icon class="el-icon--right">
            <FolderAdd />
          </el-icon>
        </el-button>
      </Toolbar>
      <vxe-grid
        :row-config="{
          keyField: '',
        }"
        :data="tableData"
        :columns="yearFeeTableColumns"
        :pager-config="pagerConfig"
        header-cell-class-name="headerCellClass"
        @page-change="handlePageChange"
        @checkbox-all="handleCheckChange"
        @checkbox-change="handleCheckChange"
        max-height="560px"
      >
        <template #actions="{ row }">
          <el-button
            v-hasPermi="['system:annualFee:query']"
            size="small"
            text
            type="info"
            @click="handleView(row)"
          >
            查看
          </el-button>
          <el-button
            v-hasPermi="['system:annualFee:edit']"
            size="small"
            text
            type="success"
            @click="handleEditRemark(row)"
          >
            修改备注
          </el-button>
        </template>
      </vxe-grid>
    </el-card>
    <YearFeeDetailModal
      v-model:visible="visible"
      :detail-params="detailParams"
    />
  </div>
</template>

<style lang="scss" scoped>

</style>
